import org.jcsp.lang.Alternative;
import org.jcsp.lang.AltingChannelInputInt;
import org.jcsp.lang.CSProcess;
import org.jcsp.lang.ChannelOutputInt;


	class JcspService 
	implements CSProcess{ 
	private AltingChannelInputInt in[]  = 
	new AltingChannelInputInt[2]; 
	private ChannelOutputInt toServer; 
	public JcspService (AltingChannelInputInt fromChef, 
	AltingChannelInputInt fromServer, 
	ChannelOutputInt toServer){ 
	this.in[0]    = fromChef; 
	this.in[1]    = fromServer; 
	this.toServer= toServer; 
	}
	public void run(){  // Service 
	int numChicks = 0; 
	int index; 
	boolean ready[] = new boolean[2]; 
	Alternative alt = new Alternative(in); 
	ready[0] = true; 
	while(true){ 
	ready[1] = (numChicks > 0); 
	index = alt.select(ready); 
	if(index == 0){ 
	numChicks = in[0].read(); 
	//nap(3000); 
	in[0].read(); 
	} 
	else{ 
	in[1].read(); 
	numChicks--; 
	toServer.write(1); 
	} } } }

